/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ThemSinhVien.java
 *
 * Created on Dec 3, 2011, 11:30:36 AM
 */
package aptech;
import data.ConnectToDatabase;
import data.Khoa;
import data.Lop;
import java.io.File;
import javax.swing.JFileChooser;
import data.Sinhvien;
import java.text.SimpleDateFormat;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
/**
 *
 * @author RUOL
 */
public class ThemSinhVien extends javax.swing.JInternalFrame {
    File []ds;
private Vector<Lop> dsl = new Vector<Lop>();
    /** Creates new form ThemSinhVien */
    public ThemSinhVien() {
        initComponents();
        Dienlop();
    }
private void Dienlop()
    {
         Lop lp = new Lop();
        dsl = lp.DanhSachLop();
        DefaultComboBoxModel dcb = new DefaultComboBoxModel();
        for(Lop d : dsl)
            dcb.addElement(d.getTenlop());
        this.jComboBoxlop.setModel(dcb);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        gioitinh = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        diachi = new javax.swing.JTextField();
        textngaysinh = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        hoten = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        dienthoai = new javax.swing.JTextField();
        email = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        masv = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        mota = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        Themsv = new javax.swing.JButton();
        hinh = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jComboBoxlop = new javax.swing.JComboBox();

        jFileChooser1.setName("jFileChooser1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(aptech.AptechApp.class).getContext().getResourceMap(ThemSinhVien.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        gioitinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nam", "Nữ" }));
        gioitinh.setName("gioitinh"); // NOI18N
        jPanel1.add(gioitinh, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 97, 130, -1));

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 92, 22));

        diachi.setText(resourceMap.getString("diachi.text")); // NOI18N
        diachi.setName("diachi"); // NOI18N
        jPanel1.add(diachi, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 153, 360, -1));

        textngaysinh.setText(resourceMap.getString("textngaysinh.text")); // NOI18N
        textngaysinh.setName("textngaysinh"); // NOI18N
        jPanel1.add(textngaysinh, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 125, 130, -1));

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 205, 92, 22));

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 179, 92, 22));

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 151, 92, 22));

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 123, 92, 22));

        hoten.setText(resourceMap.getString("hoten.text")); // NOI18N
        hoten.setName("hoten"); // NOI18N
        jPanel1.add(hoten, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 40, 170, -1));

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 229, 92, 22));

        dienthoai.setText(resourceMap.getString("dienthoai.text")); // NOI18N
        dienthoai.setName("dienthoai"); // NOI18N
        jPanel1.add(dienthoai, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 181, 360, -1));

        email.setText(resourceMap.getString("email.text")); // NOI18N
        email.setName("email"); // NOI18N
        jPanel1.add(email, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 207, 360, -1));

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N
        jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 39, 92, 22));

        masv.setText(resourceMap.getString("masv.text")); // NOI18N
        masv.setName("masv"); // NOI18N
        jPanel1.add(masv, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 13, 170, -1));

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 67, 92, 22));

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        mota.setColumns(20);
        mota.setRows(5);
        mota.setName("mota"); // NOI18N
        jScrollPane1.setViewportView(mota);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(133, 257, 360, -1));

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N
        jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 95, 92, 22));

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 257, 92, 22));

        Themsv.setText(resourceMap.getString("Themsv.text")); // NOI18N
        Themsv.setName("Themsv"); // NOI18N
        Themsv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ThemsvActionPerformed(evt);
            }
        });
        jPanel1.add(Themsv, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 360, -1, -1));

        hinh.setText(resourceMap.getString("hinh.text")); // NOI18N
        hinh.setName("hinh"); // NOI18N
        jPanel1.add(hinh, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 70, 170, -1));

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 70, -1, -1));

        jComboBoxlop.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "l1", "l2" }));
        jComboBoxlop.setName("jComboBoxlop"); // NOI18N
        jPanel1.add(jComboBoxlop, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 230, 100, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 518, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ThemsvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ThemsvActionPerformed
        Sinhvien sv = new Sinhvien();
        sv.setMasv(this.masv.getText());
        sv.setHoten(this.hoten.getText());
        sv.setHinh(this.hinh.getText());
        sv.setGioitinh(this.gioitinh.getSelectedItem().toString());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sv.setNgaysinh(sdf.parse(this.textngaysinh.getText()));
        sv.setDiachi(this.diachi.getText());
        sv.setDienthoai(this.dienthoai.getText());
        sv.setEmail(this.email.getText());
        sv.setMalop(this.jComboBoxlop.getSelectedItem().toString());
        sv.setMota(this.mota.getText());
        
        if(sv.XulyThemSinhVien())
            JOptionPane.showMessageDialog(null, "Thêm sinh viên thành công ! ");
        else
            JOptionPane.showMessageDialog(null, "Thao tác thêm sinh viên thất bại. Cố gắn thử lại lần sau ! ");
}//GEN-LAST:event_ThemsvActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        JFileChooser jf=new JFileChooser();
        jf.setMultiSelectionEnabled(true);
        jf.setFileFilter(new giffiler());
        if (jf.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) {
            ds=jf.getSelectedFiles();
            if(ds.length==0)
            {
                JOptionPane.showMessageDialog(null, "Vui long chon file");
            }
            else
            {
                for(File f:ds)
                {
                this.hinh.setText(f.getName());
                }
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Themsv;
    private javax.swing.JTextField diachi;
    private javax.swing.JTextField dienthoai;
    private javax.swing.JTextField email;
    private javax.swing.JComboBox gioitinh;
    private javax.swing.JTextField hinh;
    private javax.swing.JTextField hoten;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBoxlop;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField masv;
    private javax.swing.JTextArea mota;
    private javax.swing.JTextField textngaysinh;
    // End of variables declaration//GEN-END:variables
}
